package com.tencent.ied.bk.service.impl;

import com.tencent.ied.bk.constant.CommonConstant;
import com.tencent.ied.bk.entity.BaseAbstractInfo;
import com.tencent.ied.bk.common.LocalStore;
import com.tencent.ied.bk.service.WordIndexService;

/**
 * @author chen_yu
 * @date 2021/3/11 4:36
 */
public class WordIndexServiceImpl implements WordIndexService {

    @Override
    public void updateWordIndex(BaseAbstractInfo baseAbstractInfo) {
        for (String word : baseAbstractInfo.getWords()) {
            String lowerCaseWord = word.toLowerCase();
            //插入倒排索引
            int[] indexArray = LocalStore.WORD_INDEX.computeIfAbsent(lowerCaseWord, k -> new int[CommonConstant.ABSTRACT_NUM_LIMIT]);
            indexArray[baseAbstractInfo.getId()]++;
        }
    }
}
